package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IWarehouseDAO;
import com.AAL.Model.City;
import com.AAL.Model.WareHouse;
import com.AAL.Utils.HibernateUtil;

public class WarehouseDAO implements IWarehouseDAO {

	@Override
	public WareHouse getWareHouse(int warehouseID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		WareHouse wareHouse = (WareHouse) session.load(WareHouse.class,
				(short) warehouseID);
		return wareHouse;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<WareHouse> getLstWareHouses() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<WareHouse> lsWareHouses = null;
		try {
			lsWareHouses = (List<WareHouse>) session.createQuery(
					"from WareHouse").list();
		} catch (HibernateException e) {		
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lsWareHouses;
	}

	@Override
	public List<WareHouse> getLstWareHousesByCity(City city) {
		// TODO Auto-generated method stub
		return null;
	}

}
